﻿#pragma once
#include "CoreMinimal.h"
#include "bytertc_room_event_handler.h"
#include "bytertc_video_event_handler.h"
#include "Subsystems/WorldSubsystem.h"
#include "VolcEngineRTCSubsystem.generated.h"

DECLARE_LOG_CATEGORY_EXTERN(VRTCLog, Log, All);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnRoomMessageReceived, const FString&, UID, const FString&, ReceivedMessage);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_FourParams(FOnRoomStateChanged, const FString&, room_id, const FString&, uid, int, state, const FString&, extra_info);
namespace bytertc
{
	class IRTCRoom;
	class IRTCVideo;
}

UCLASS()
class VOLCENGINERTCWITHUE5_API UVolcEngineRTCSubsystem
	: public UWorldSubsystem
	 , public bytertc::IRTCVideoEventHandler,
	   public bytertc::IRTCRoomEventHandler
{
	GENERATED_BODY()
public:
	virtual void Initialize(FSubsystemCollectionBase& Collection) override;
	virtual void Deinitialize() override;

	UFUNCTION(BlueprintCallable, Category = "UVolcEngine")
	void InitVolcEngine(const FString& RoomID, const FString& UID, const FString& APPID, const FString& TOKEN);
private:
	virtual void onRoomStateChanged(const char* room_id, const char* uid, int state, const char* extra_info) override;
	virtual void onRoomMessageReceived(const char* uid, const char* message) override;

private:

private:
	bytertc::IRTCVideo* m_video = nullptr;
	bytertc::IRTCRoom* m_room = nullptr;

public:
	UPROPERTY(BlueprintAssignable)
	FOnRoomMessageReceived OnRoomMessageReceived;
	
	UPROPERTY(BlueprintAssignable)
	FOnRoomStateChanged OnRoomStateChanged;
};